package com.ruoyi.mobile.service.impl;

import com.ruoyi.mobile.domain.MobileMonthStatisticsVo;
import com.ruoyi.mobile.mapper.MobileMonthStatisticsMapper;
import com.ruoyi.mobile.service.IMobileCarInfoStatistics;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * @Author Jack_Lee
 * @Date 2024/7/16
 * 车辆信息统计
 */
@Service
public class MobileCarInfoStatisticsImpl implements IMobileCarInfoStatistics {

    @Resource
    MobileMonthStatisticsMapper statisticsMapper;

    @Override
    public List<MobileMonthStatisticsVo> MonthStatistics(Map<String, Object> paramMap) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();

        if (paramMap.get("startTime") == null) {
            // 设置为当前月的第一天
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            paramMap.put("startTime", sdf.format(calendar.getTime()));
        }

        if (paramMap.get("endTime") == null) {
            // 设置为当前月的最后一天
            calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
            paramMap.put("endTime", sdf.format(calendar.getTime()));
        }

        // 打印参数以进行调试
        System.out.println("Parameters-------------------->: " + paramMap);

        List<MobileMonthStatisticsVo> mobileMonthStatisticsVos = statisticsMapper.statisticsMonthData(paramMap);
        System.out.println("monthStatisticsVos ==================== " + mobileMonthStatisticsVos);
        return mobileMonthStatisticsVos;
    }
}
